package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysParking;

import com.gec.model.vo.SysParkingQueryVo;
import com.gec.system.service.SysParkingService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车位信息表 前端控制器
 * </p>
 *
 * @author Liangxj
 * @since 2023-12-06
 */
@Api(tags = "车位信息控制器")
@RestController
@RequestMapping("/admin/system/sysParking")
public class SysParkingController {

    @Autowired
    private SysParkingService sysParkingService;

    @ApiOperation("分页查询车位列表")
    @GetMapping("/{page}/{limit}")
    public Result findPage(@PathVariable Long page,
                           @PathVariable Long limit,
                           SysParkingQueryVo vo){

        IPage<SysParking> page1 = new Page<>(page,limit);
        page1 = this.sysParkingService.selectPage(page1,vo);
        return Result.ok(page1);
    }

    //查看全部
    @ApiOperation("获取全部车位信息")
    @GetMapping("/findAll")
    public Result findAll() {
        List<SysParking> list = this.sysParkingService.list();
        return Result.ok(list);
    }

    //    新增
    @ApiOperation("新增车位信息")
    @PostMapping("/addParking")
    public Result addParking(@RequestBody SysParking sysParking) {
        boolean res = this.sysParkingService.save(sysParking);
        if (res) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    // 修改
    //1.根据id 去得到当前分类
    @ApiOperation("根据id获取车位信息")
    @GetMapping("/findParkingById/{id}")
    public Result findParkingById(@PathVariable Long id)
    {
        SysParking sysParking = this.sysParkingService.getById(id);
        return Result.ok(sysParking);
    }

    // 实现修改
    @ApiOperation("修改车位信息")
    @PostMapping("/updateParking")
    public Result updateParking(@RequestBody SysParking sysParking)
    {
        boolean b = this.sysParkingService.updateById(sysParking);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }

//    根据单个id 删除数据
    @ApiOperation("根据id删除账号")
    @DeleteMapping("/removeParkingById/{id}")
    public Result removeParkingById(@PathVariable Long id){

        boolean b = this.sysParkingService.removeById(id);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

    // 批量删除
    @ApiOperation("批量删除车位信息")
    @DeleteMapping("/removeParkingByIds")
    public Result removeParkingByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.sysParkingService.removeByIds(ids);

        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }


    // 更改用户状态
    @ApiOperation("更改车位状态")
    @GetMapping("/updateParkingStatus/{id}/{status}")
    public Result updateParkingStatus(@PathVariable Long id,
                               @PathVariable Integer status)
    {
        this.sysParkingService.updateParkingStatus(id,status);
        return Result.ok();
    }


}

